const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const MessageSchema = new Schema({
    // 群组与个人的需要区分
    id: String, // a发给b的与b发给a的id应一致
    // from 与 to是相对的
    from: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    to: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    readed: Boolean,
    content: String,
    create_time: {
        type: Date,
        default: Date.now
    },
    type: {
        type: String,
        enum: ['text', 'image', 'code'],
        default: 'text',
    },
    toWho: {
        type: String,
        enum: ['group', 'person'],
        default: 'person', 
    }
});

const Message = mongoose.model('Message', MessageSchema);

module.exports = Message;